package com.example.yrdev.ordering_system.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yrdev.ordering_system.R;

/**
 * Created by yrdev on 8/18/16.
 */
public class GridViewAdapter extends BaseAdapter {
    Integer []imageArray;
    String[]titleArray;

    Context context;
    LayoutInflater inflater;

    public GridViewAdapter(Context contexts,Integer[]imageArray){
        this.imageArray=imageArray;
        this.context=contexts;
        inflater=LayoutInflater.from(contexts);

    }

    public GridViewAdapter(Context contexts,Integer[]imageArray,String[]titleArray){
        this.imageArray=imageArray;
        this.context=contexts;
        this.titleArray=titleArray;

        inflater=LayoutInflater.from(contexts);

    }
    @Override
    public int getCount() {
        return imageArray.length;
    }

    @Override
    public Object getItem(int i) {
        return imageArray[i];
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view==null){
            view=inflater.inflate(R.layout.option_grid_layout,null);

        }
        ImageView optionIM=(ImageView)view.findViewById(R.id.optionIM);
        optionIM.setImageResource(imageArray[i]);
        TextView textView=(TextView)view.findViewById(R.id.optionTxt);
        if (titleArray!=null && titleArray.length>i){
            textView.setText(titleArray[i]);
        }
        view.setId(imageArray[i]);

//        LinearLayout linearLayout=new LinearLayout(this.context);
//        linearLayout.setWeightSum(1);
//         linearLayout.setBackgroundColor(Color.parseColor("#dcf3f8"));
//        linearLayout.setGravity(Gravity.CENTER);
//        ImageView img=new ImageView(this.context);
//        img.setImageResource(imageArray[i]);
//
//        img.setLayoutParams(new GridView.LayoutParams(250, 250));
//
//        img.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        linearLayout.addView(img);
//        linearLayout.setId(imageArray[i]);
        return view;

    }

    @Override
    public long getItemId(int i) {
        return imageArray[i];
    }
}
